package com.top.art.controller;


import com.top.art.bo.BaseBO;
import com.top.art.bo.RulerBO;
import com.top.art.bo.RulerQueryBO;
import com.top.art.manager.RulerManager;
import com.top.art.vo.CourseVO;
import com.top.art.vo.ProvinceVO;
import com.top.art.vo.ResVO;
import com.top.art.vo.ResultList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hjh
 * @since 2020 -10-07
 */
@RestController
@RequestMapping("/ruler")
public class RulerController {


    @Autowired
    private RulerManager rulerManager;


    /**
     * Create res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "/create")
    public ResVO<Boolean> create(@Validated @RequestBody RulerBO bo) {
        return new ResVO<>(rulerManager.create(bo));
    }


    /**
     * Page res vo.
     *
     * @param province the province
     * @return the res vo
     */
    @GetMapping(value = "/query")
    public ResVO<RulerBO> query(@RequestParam String province) {
        Assert.hasLength(province, "province is null");
        RulerBO page = rulerManager.query(province);
        return new ResVO<>(page);
    }

    /**
     * Update res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "/update")
    public ResVO<Boolean> update(@Validated @RequestBody RulerQueryBO bo) {
        boolean result = rulerManager.update(bo);
        return new ResVO<>(result);
    }


    @GetMapping(value = "/listProvince")
    public ResVO<List<ProvinceVO>> listProvince() {
        return new ResVO<>(rulerManager.queryProvince());
    }

    @PostMapping(value = "/listRules")
    public ResVO<ResultList<RulerBO>> listRules(@RequestBody BaseBO bo) {
        return new ResVO<>(rulerManager.query(bo));
    }

    @GetMapping(value = "/queryCourse")
    public ResVO<List<CourseVO>> queryCourse(String province) {
        return new ResVO<List<CourseVO>>(rulerManager.queryCourse(province));
    }

}
